package com.ssfeng.youxia.controller;

import com.ssfeng.youxia.publisher.DemoPublisher;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

/**
 * Created by liyuhang on 2019-09-12.
 * 改类用于功能测试
 */
@Controller
public class TestController {

    private static final Logger logger = LoggerFactory.getLogger(TestController.class);


    @Autowired
    private MappingJackson2JsonView mappingJackson2JsonView;

    @Autowired
    private DemoPublisher demoPublisher;

    @RequiresRoles("admin")
    @RequestMapping("/testRole")
    public ModelAndView testRole(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setView(mappingJackson2JsonView);
        modelAndView.addObject("msg", "我是管理员");
        return modelAndView;
    }

    @RequestMapping("/roles")
    public ModelAndView rolesFiter(){
        System.out.println("debugger:"+logger.isDebugEnabled());
        System.out.println("info:"+logger.isInfoEnabled());
        System.out.println("warn:"+logger.isWarnEnabled());
        System.out.println("error:"+logger.isErrorEnabled());
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setView(mappingJackson2JsonView);
        modelAndView.addObject("msg", "拦截器");
        return modelAndView;
    }


    @GetMapping(value = "/publish")
    public ModelAndView publish(){
        demoPublisher.publish("xxoo");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setView(mappingJackson2JsonView);
        modelAndView.addObject("msg", "hello");
        return modelAndView;
    }
}
